<template>
	<div>
		<!--:model="tenant" 数据双向绑定-->
		<!--ref="tenantForm" id="tenantForm",给form去一个名字-->
		<!--:rules="formRules" 校验规则-->
		<el-form :model="employee" ref="tenantForm"  label-position="left" label-width="100px" class="demo-ruleForm login-container">
			<h3 class="title">绑定账号</h3>
			<el-form-item prop="companyName"label="用户名">
				<el-input type="text" v-model="employee.username" auto-complete="off" placeholder="请输入公司名称！"></el-input>
			</el-form-item>
			<el-form-item prop="companyNum" label="密码">
				<el-input type="text" v-model="employee.password" auto-complete="off" placeholder="请输入座机！"></el-input>
			</el-form-item>
			<el-form-item style="width:100%;">
				<el-button type="primary" style="width:100%;" @click.native.prevent="bind" >绑定</el-button>
			</el-form-item>
		</el-form>

		<!--新增界面-->
		<el-dialog title="选择地址" :visible.sync="mapDialogVisible"  :close-on-click-modal="false">
			<baidu-map :center="{lng: 116.403765, lat: 39.914850}" :zoom="11">
				<bm-auto-complete v-model="keyword" :sugStyle="{zIndex: 2100}">
					<div style="margin-bottom:10px">
						<input  id="searchInput" type="text" placeholder="请输入关键字" class="searchinput"/>
						<el-button @click="confirmAdd" type="success" >确定</el-button>
					</div>
				</bm-auto-complete>
				<bm-view class="bmap"/>
				<bm-local-search :keyword="keyword" :auto-viewport="true" :panel="false"></bm-local-search>
			</baidu-map>
		</el-dialog>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				employee: {
					username: '',
					password: '',
					openId:''
				}
			};
		},
		methods: {
			bind(){
				this.$http.post("/wechat/weixin/bind",this.employee).then(res=>{
					//登录成功
					sessionStorage.setItem('user', JSON.stringify(res.data.data.user));

					sessionStorage.setItem('sessionId', res.data.data.sessionId);

					this.$router.push({ path: '/echarts' });
				}).catch(error => {
					console.log(error);
					alert(error.message);
				})
			}
		},
		mounted(){
			var openid = location.href.split("?")[1];
			let openId = openid.split("=")[1];
			if(openId.indexOf("#")> -1){
				openId = openId.split("#")[0];
			}

			this.employee.openId = openId;
		}
	}

</script>